package components
{
	import flash.events.MouseEvent;
	
	import mx.controls.Button;
	
	/** a button that can be dragged around **/
	public class DragableButton extends Button
	{
		public function DragableButton()
		{
			super();
			this.addEventListener(MouseEvent.MOUSE_DOWN, drag);
			this.addEventListener(MouseEvent.MOUSE_UP, drag);
			this.addEventListener(MouseEvent.MOUSE_MOVE, drag);
		}
		
		public var dragging:Boolean = false;
		public function drag(event:MouseEvent):void
		{
			if(event.type == MouseEvent.MOUSE_DOWN)
			{
				dragging = true;
			}
			if(event.type == MouseEvent.MOUSE_UP)
			{
				dragging = false;
			}
			if(event.type == MouseEvent.MOUSE_MOVE)
			{
				if(dragging)
				{
					this.x = mouseX;
					this.y = mouseY;
				}
			}
		}
	}
}